package com.eshore.thrpc.client.thrift;

import org.apache.thrift.TServiceClient;
import org.apache.thrift.TServiceClientFactory;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;

import com.eshore.thrpc.client.IClient;

/**
 * 
 * 阻塞客户端
 * 
 * 
 *   
 * @author zhouzhixiang  
 * @date 2016年12月12日 上午9:48:19 
 * @since 1.0
 */
public class ThriftBlockingClient implements IClient{
	
	/** {@link TServiceClientFactory }<{@link TServiceClient}> */
    private TServiceClientFactory<TServiceClient> clientFactory;
    
    public ThriftBlockingClient(TServiceClientFactory<TServiceClient> clientFactory){
    	this.clientFactory = clientFactory;
    }
	
	@Override
	public TServiceClient getClient(String ip,int port,int timeout) throws Exception {
		TSocket tsocket = new TSocket(ip, port, timeout);
        TProtocol protocol = new TCompactProtocol(tsocket);
        TServiceClient client = clientFactory.getClient(protocol);
        tsocket.open();
        return  client;
	}
	
}
